import 'package:english_words/english_words.dart';
import 'package:flutter/material.dart';

class RandomWordsRoute extends StatefulWidget {
  const RandomWordsRoute({Key? key}) : super(key: key);

  @override
  State<StatefulWidget> createState() => _RandomWordsRouteState();
}

class _RandomWordsRouteState extends State<RandomWordsRoute> {
  String varchar = '';

  @override
  void initState() {
    super.initState();
    _randomStr();
  }

  void _randomStr() {
    setState(() {
      varchar = WordPair.random().asString;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text("随机生成字符串"),
      ),
      body: Center(
        child: Column(
          children: [
            Text(
              varchar,
              style: const TextStyle(fontSize: 32, fontWeight: FontWeight.w700),
            ),
            Padding(
              padding: const EdgeInsets.only(top: 20),
              child: ElevatedButton(
                onPressed: _randomStr,
                child: const Text("随机生成字符串"),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
